/**
 * Created by Administrator on 2017/7/17.
 */

import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.function.Supplier;

/**
 * @author linruoyu
 **/
public class MainTest {
    public static void main(String[] args) {
        MainTest test = new MainTest();
        test.lambdatest();
//        test.functionLambdatest();
//        test.systempropertiestest();
//        test.filter();


    }

    void systempropertiestest() {
        Properties props = System.getProperties();
        System.out.println(props.getProperty("java.home"));

        System.out.println("java_vendor:" + System.getProperty("java.vendor"));
        System.out.println("java_vendor_url:"
                + System.getProperty("java.vendor.url"));
        System.out.println("java_home:" + System.getProperty("java.home"));
        System.out.println("java_class_version:"
                + System.getProperty("java.class.version"));
        System.out.println("java_class_path:"
                + System.getProperty("java.class.path"));
        System.out.println("os_name:" + System.getProperty("os.name"));
        System.out.println("os_arch:" + System.getProperty("os.arch"));
        System.out.println("os_version:" + System.getProperty("os.version"));
        System.out.println("user_name:" + System.getProperty("user.name"));
        System.out.println("user_home:" + System.getProperty("user.home"));
        System.out.println("user_dir:" + System.getProperty("user.dir"));
        System.out.println("java_vm_specification_version:"
                + System.getProperty("java.vm.specification.version"));
        System.out.println("java_vm_specification_vendor:"
                + System.getProperty("java.vm.specification.vendor"));
        System.out.println("java_vm_specification_name:"
                + System.getProperty("java.vm.specification.name"));
        System.out.println("java_vm_version:"
                + System.getProperty("java.vm.version"));
        System.out.println("java_vm_vendor:"
                + System.getProperty("java.vm.vendor"));
        System.out
                .println("java_vm_name:" + System.getProperty("java.vm.name"));
        System.out.println("java_ext_dirs:"
                + System.getProperty("java.ext.dirs"));
        System.out.println("file_separator:"
                + System.getProperty("file.separator"));
        System.out.println("path_separator:"
                + System.getProperty("path.separator"));
        System.out.println("line_separator:"
                + System.getProperty("line.separator"));

    }

    void functionLambdatest() {
        new FunctionalDefaultMethodsImpl().notRequire();

        FunctionalDefaultMethods functionalDefaultMethods = DefaulableFactory.create(FunctionalDefaultMethodsImpl::new);
        functionalDefaultMethods.notRequire();

        //第一种方法引用是构造器引用，它的语法是Class::new，或者更一般的Class< T >::new。请注意构造器没有参数。
        final Car car = Car.create(Car::new);
        final List<Car> cars = Arrays.asList(car);
        //第二种方法引用是静态方法引用，它的语法是Class::static_method。请注意这个方法接受一个Car类型的参数。
        cars.forEach(Car::collide);
        //第三种方法引用是特定类的任意对象的方法引用，它的语法是Class::method。请注意，这个方法没有参数。
        cars.forEach(Car::repair);
        //最后，第四种方法引用是特定对象的方法引用，它的语法是instance::method。请注意，这个方法接受一个Car类型的参数
        final Car police = Car.create(Car::new);
        cars.forEach(police::follow);
    }

    void lambdatest() {
        Arrays.asList("a", "b", "c").forEach(e -> System.out.println(e));
        Arrays.asList("a", "b", "c").sort((a, b) -> a.compareTo(b));
        Arrays.asList("a", "b", "c").forEach(e -> new FunctionalDefaultMethodsImpl().method(e));
    }

    public static class Car {
        public static Car create(final Supplier<Car> supplier) {
            return supplier.get();
        }

        public static void collide(final Car car) {
            System.out.println("Collided " + car.toString());
        }

        public void follow(final Car another) {
            System.out.println("Following the " + another.toString());
        }

        public void repair() {
            System.out.println("Repaired " + this.toString());
        }
    }

    private void filter(){
        String s="09AD221D7ADE609EB18AA2C1F1FC1DB973B46A9AD1B11C5306BE4670B9CE8EB3";
        System.out.println(s.length());
    }
}

